/* From: rc2-nyc : 16740 */
// yui substitute
(function(root){

	var uniq = 1,
		sel = function(e){
			return jQuery('string' === typeof e ? '#' + e : e);
		},
		deprecated = function(a){
			huff.beta && console.warn(a + ' is deprecated');
		}

	root.YAHOO = {

		util: {

			Event: {

				on: function(e, event, handler, cntx, overide){
					deprecated('YAHOO.util.Event.on', arguments);
					sel(e).bind(event, function(e){
						overide === true
							? handler.apply(cntx || this, arguments)
							: handler.call(overide || this, e, cntx);
					});
				},

				onAvailable: function(s, fn){
					deprecated('YAHOO.util.Event.onAvailable', arguments);

					if (sel(s).length)
						return 'function' === typeof fn && fn();

					var k = 0,
						i = setInterval(function(){
							if (sel(s).length){
								'function' === typeof fn && fn();
								clearInterval(i);
							} else {
								2000 < ++k && clearInterval(i);
							}
						}, 100);
				},

				addListener: function(e, event, handler, cntx){
					deprecated('YAHOO.util.Event.addListener', arguments);
					sel(e).bind(event, function(){
						handler.apply(cntx, arguments);
					});
				},

				removeListener: function(e, event){
					deprecated('YAHOO.util.Event.removeListener', arguments);
					sel(e).unbind(event);
				},

				getTarget: function(e){
					deprecated('YAHOO.util.Event.getTarget', arguments);
					return e.currentTarget;
				},

				purgeElement: function(e){
					deprecated('YAHOO.util.Event.purgeElement', arguments);
					sel(e).unbind();
				}

			},

			Dom: {

				get: function(){
					deprecated('YAHOO.util.Dom.get', arguments);
					return document.getElementById.apply(document, arguments);
				},

				setStyle: function(e, prop, val){
					deprecated('YAHOO.util.Dom.setStyle', arguments);
					sel(e).css(prop, val);
				},

				getStyle: function(e, prop){
					deprecated('YAHOO.util.Dom.getStyle', arguments);
					return sel(e).css(prop);
				},

				addClass: function(e, c){
					deprecated('YAHOO.util.Dom.addClass', arguments);
					sel(e).addClass(c);
				},

				removeClass: function(e, c){
					deprecated('YAHOO.util.Dom.removeClass', arguments);
					sel(e).removeClass(c);
				},

				hasClass: function(e, c){
					deprecated('YAHOO.util.Dom.hasClass', arguments);
					return sel(e).hasClass(c);
				},

				batch: function(e, f){
					deprecated('YAHOO.util.Dom.batch', arguments);
					sel(e).each(f);
				},

				getElementsByClassName: function(c, t){
					deprecated('YAHOO.util.Dom.getElementsByClassName', arguments);
					return Array.prototype.slice.call(jQuery((t || '') + '.' + c), 0);
				},

				generateId: function(e){
					deprecated('YAHOO.util.Dom.generateId', arguments);
					var id = 'yui-gen' + (uniq++);
					sel(e).attr('id', id);
					return id;
				},

				getXY: function(e){
					deprecated('YAHOO.util.Dom.getXY', arguments);
					var offset = sel(e).offset();
					return offset ? [offset.left, offset.top] : false;
				},

				getDocumentHeight: function(){
					return jQuery(document).height();
				},

				getViewportHeight: function(){
					return jQuery(window).height();
				},

				getAncestorByClassName: function(e, c){
					return sel(e).parents('.' + c)[0] || null;
				}

			},

			Connect: {

				asyncRequest: function(method, uri, callback, postData){
					deprecated('YAHOO.util.Connect.asyncRequest', arguments);

					var response = {};

					var request = {
						url:		uri,
						type:		method,
						success:	function(data, xhr){
										response.done = true;
										'function' === typeof callback.success && callback.success.call(callback.scope || null, {
											responseText:	data,
											status:			xhr.status,
											argument:		callback.argument
										});
									},
						error:		function(){
										response.done = true;
										'function' === typeof callback.failure && callback.failure.call(callback.scope || null);
									}
					}

					callback.timeout && (request.timeout = callback.timeout);
					postData && (request.data = postData);

					jQuery.ajax(request);

					return response;
				},

				isCallInProgress: function(a){
					return !!a.done;
				}

			},

			Anim: function(e, attributes, duration, method){
				deprecated('YAHOO.util.Anim', arguments);
				e = sel(e);

				var p, from = {}, to = {},
					subscribers = [];

				for(var i in attributes) if (attributes.hasOwnProperty(i)){
					p = attributes[i];
					'from' in p && (from[i] = p.from);
					'to' in p && (to[i] = p.to);
				}

				e.css(from);

				return {
					animate: function(){
						e.animate(to, duration, function(){
							for(var i=0, l=subscribers.length; i<l; i++)
								'function' === typeof subscribers[i] && subscribers[i]();
							subscribers = [];
						});
					},

					stop: function(){
						e.stop()
					},

					onComplete: {

						subscribe: function(f){
							subscribers.push(f);
						}

					}
				}
			},

			Easing: {}

		},

		namespace: function(s){
			deprecated('YAHOO.namespace', arguments);
			return YAHOO[s] = {};
		},

		extend: function(a, b, c){
			deprecated('YAHOO.extend', arguments);
			var empty=function(){};
			empty.prototype = b.prototype;
			a.prototype = new empty();
			a.prototype.constructor = a;
			a.superclass = b.prototype;
			c && jQuery.extend(a.prototype, c);
		}

	};

})(window);
